<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:replace="dashboard/header :: header"></head>
<div th:replace="dashboard/script:: style"></div>
<style>
      .CodeMirror {border-top: 1px solid #eee; border-bottom: 1px solid #eee;}
      article {max-width: 100%;padding:10px;}
      .nav-third-level li a {
	 	padding-left: 12px;
	 	color: #696c6e;
	  }
</style>

<body>
<div class="row wrapper wrapper-content animated fadeIn">
        <div class="col-sm-2">
            <div class="ibox float-e-margins" style="border:0px;">
                <ul class="nav nav-third-level collapse in" aria-expanded="true" style="">
					<li class="selected"><a class="menuItem" href="/demo/form/button" data-index="0">并发测试</a></li>
					<li class=""><a class="menuItem" href="/demo/form/grid" data-index="1">模板测试</a></li>
					<li class=""><a class="menuItem" href="/demo/form/select" data-index="2">高场景测试</a></li>
					<li class=""><a class="menuItem" href="/demo/form/basic" data-index="3">基本表单</a></li>
					<li class=""><a class="menuItem" href="/demo/form/cards" data-index="4">卡片列表</a></li>
					<li class=""><a class="menuItem" href="/demo/form/datetime" data-index="11">日期和时间</a></li>
					<li class=""><a class="menuItem" href="/demo/form/duallistbox" data-index="12">左右互选组件</a></li>
					<li class=""><a class="menuItem" href="/demo/form/autocomplete" data-index="13">搜索自动补全</a></li>
				</ul>
            </div>
        </div>
        <div class="col-sm-10">
        
<article >
<h2>压测脚本(Scala)</h2>

<form >
<textarea id="code" name="code" wrap="hard" style="height:700px;white-space: pre-wrap;word-wrap:break-word">
object HelloWorld {
    def main(args: Array[String]): Unit = {
        println("Hello, world!")
    }
}
</textarea>
</form> 
<div style="font-size: 13px; width: 300px; height: 30px;margin-top:10px;">Key buffer: <span id="command-display"></span></div>

<button type="button" onclick="saveBtn()" class="btn btn btn-danger btn-primary">保存</button>

<script> 

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
    lineNumbers: true,
    keyMap: "vim",
    matchBrackets: true,
    showCursorWhenSelecting: true,
    theme: "ambiance",
    mode: "text/x-scala" , 
    inputStyle: "contenteditable"
});
editor.setSize('auto','500px');

function saveBtn(){
    layer.prompt({title: '请输入场景名称'}, function(text, index){
    	
	   layer.close(index);
	   var scriptDesc = editor.getValue(); 
	   scriptDesc = scriptDesc.replace(/[\r\n]/g, '|');
	   
	   var id = "" ;  
	   var script = {
			taskName: text,
			scriptType: "scala",
			scriptContent: scriptDesc,
			id: id
		};
	   
	   var saveUrl = ctx+"portal/auto/autoTask/save" ;
	   $.operate.save(saveUrl , script);
	});
}

CodeMirror.commands.save = function() {
	
	var totalLines = editor.lineCount();
    editor.autoFormatRange({line:0, ch:0}, {line:totalLines});
	
	var code = editor.getValue() ; 
	console.log(editor.getValue()) 
	
	code = code.replace(/[\r\n]/g, '|');
	
	$.post(ctx+'portal/auto/autoTask/code' , {code:code} , function(response){
		console.log("response = " + response) ;
	}) ; 
	
};

var commandDisplay = document.getElementById('command-display');
var keys = '';
CodeMirror.on(editor, 'vim-keypress',
function(key) {
    keys = keys + key;
    commandDisplay.innerHTML = keys;
});
CodeMirror.on(editor, 'vim-command-done',
function(e) {
    keys = '';
    commandDisplay.innerHTML = keys;
}); 
</script>

</article>

        </div>
    </div>
	<footer th:replace="dashboard/footer :: footer"></footer>

</body>
</html>


